package cn.kmbeast.service.impl;

import cn.kmbeast.mapper.NewsSaveMapper;
import cn.kmbeast.pojo.api.ApiResult;
import cn.kmbeast.pojo.api.Result;
import cn.kmbeast.pojo.dto.query.extend.NewsSaveDto;
import cn.kmbeast.pojo.entity.NewsSave;
import cn.kmbeast.pojo.vo.NewsSaveVo;
import cn.kmbeast.service.NewsSaveService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class NewsSaveServiceImpl implements NewsSaveService {

    @Resource
    private NewsSaveMapper newsSaveMapper;

    @Override
    public Result<Void> save(NewsSave newsSave) {
        //通过date拿到当前的时间
        newsSave.setCreateTime(new Date());
        newsSaveMapper.save(newsSave);
        return ApiResult.success();
    }

    @Override
    public Result<List<NewsSaveVo>> query(NewsSaveDto newsSaveDto) {
        List<NewsSaveVo> queryData = newsSaveMapper.query(newsSaveDto);
        Integer i = newsSaveMapper.queryCount(newsSaveDto);
        return ApiResult.success(queryData,i);
    }

    @Override
    public Result<Void> batchDelete(List<Long> ids) {
        newsSaveMapper.batchDelete(ids);
        return ApiResult.success();
    }

    @Override
    public Result<Void> delete(NewsSaveDto newsSaveDto) {
        newsSaveMapper.delete(newsSaveDto);
        return ApiResult.success();
    }


}
